﻿using B.R.RabbitRoot.Domain;
using B.R.RabbitRoot.ErrorCode;
using B.R.RabbitRoot.Infrastructure.Interface;
using B.R.RabbitRoot.Write.API.Applications.Commands.ImgCommands;
using MediatR;
using Microsoft.AspNetCore.Mvc;

namespace B.R.RabbitRoot.Write.API.Applications.Commandhandlers.ImgCommandHandlers
{
    public class ImageTableQueryCommandHandler : IRequestHandler<ImageTableQueryCommand, APIResult<List<ImageTable>>>
    {
        private readonly IBaserepository<ImageTable> _imageTableRedsitoty;

        public ImageTableQueryCommandHandler(IBaserepository<ImageTable> imageTableRedsitoty)
        {
            _imageTableRedsitoty = imageTableRedsitoty;
        }
        /// <summary>
        /// 图片查询命令
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<APIResult<List<ImageTable>>> Handle(ImageTableQueryCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<ImageTable>> result= new APIResult<List<ImageTable>>();
            result.Code = ResultCode.显示成功;
            result.Message = ResultCode.显示成功.ToString();
            result.Data=_imageTableRedsitoty.GetAll().Where(m => m.SourceInfoId == request.SourceInfoId).ToList();
            return await Task.FromResult(result);
        }
    }
}
